package io;

import equation.Equation;
import equation.Exercise;

import java.util.ArrayList;

public class Check {
    private int rightAnswer;
    private int wrongAnswer;
    private int count;

    public int getRightAnswer() {
        return rightAnswer;
    }

    public void setRightAnswer(int rightAnswer) {
        this.rightAnswer = rightAnswer;
    }

    public int getWrongAnswer() {
        return wrongAnswer;
    }

    public void setWrongAnswer(int wrongAnswer) {
        this.wrongAnswer = wrongAnswer;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Check() {
        rightAnswer = 0;
        wrongAnswer = 0;
    }

    public void checkAnswer(Exercise exercise, Answer answer) {
        ArrayList<Equation> equationList = exercise.getEquationList();
        this.count = equationList.size();
        ArrayList<Integer> answerList = answer.getAnswerList();
        for (int i = 0; i < equationList.size(); i++) {
            if(equationList.get(i).getResult()==answerList.get(i)){
                rightAnswer++;
            }else {
                wrongAnswer++;
            }
        }
        this.setRightAnswer(rightAnswer);
        this.setWrongAnswer(wrongAnswer);
    }

    public void printCheck(){
        System.out.println("本次练习批改结果：");
        System.out.println("算是总数："+count);
        System.out.println("正确："+rightAnswer);
        System.out.println("错误："+wrongAnswer);
    }
}
